package com.ironman.analyze.orm.flex.config;

import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.spring.boot.MyBatisFlexCustomizer;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;

/**
 * description TODO
 * company 铁人科技
 *
 * @author 陈浩杰
 * @date 2023/6/28 13:28
 */
@Slf4j
@Configuration
@MapperScan(value = {MybatisFlexConfig.MAPPER_SCAN})
public class MybatisFlexConfig implements MyBatisFlexCustomizer {

    static final String MAPPER_SCAN = "com.ironman.analyze.orm.flex";

    @Override
    public void customize(FlexGlobalConfig globalConfig) {
        //开启审计功能
        AuditManager.setAuditEnable(true);
        //设置 SQL 审计收集器
        AuditManager.setMessageCollector(message -> log.info("Flex exec sql took {} ms >>>  {}", message.getElapsedTime(), message.getFullSql()));
    }
}